﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;

namespace HouseAgencySite.Utils
{
    /// <summary>
    /// example: http://emailsender.codeplex.com/
    /// </summary>
    public class SmtpSendingBase:EmailSenderBase
    {
        #region Settings
        protected override void ParseSetUpXml(XElement element)
        {
            var smtp = element.Element("Smtp");

            if (smtp == null)
                throw new SetUpException("Smtp element does not exist");

            HostName = smtp.Element("HostName").Value;
            Port = smtp.Element("Port").ParseInt(25);
            TimeOut = smtp.Element("TimeOut").ParseInt(3000);
            UserName = smtp.Element("UserName").ToValueOrEmpty();
            Password = smtp.Element("Password").ToValueOrEmpty();

            From = smtp.Element("From").Value;
            To = smtp.Element("To").Value;
        }

        public string HostName { get; set; }
        public int Port { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }
        public string From { get; set; }
        public string To { get; set; }
        public int TimeOut { get; set; }

        #endregion


        #region Protected

        protected SmtpSender CreateSender()
        {
            return new SmtpSender(HostName)
            {
                Port = this.Port,
                UserName = this.UserName,
                Password = this.Password,
                Timeout = TimeOut
            };
        }

        #endregion

    }
}